package com.qsl.common.result;

import com.qsl.common.enums.ResponseCodeEnum;

import java.io.Serializable;

public class ResultEntity<T> implements Serializable {
    private int code;
    private String message;
    private T data;
    private long timestamp;

    public ResultEntity() {
    }

    public ResultEntity(int code, String message, T data, long timestamp) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.timestamp = timestamp;
    }

    public ResultEntity(int code, String message, long timestamp) {
        this.code = code;
        this.message = message;
        this.timestamp = timestamp;
    }



    public static <T> ResultEntity<T> success() {
        return new ResultEntity<T>(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMessage(), null, System.currentTimeMillis());

    }

    public static <T> ResultEntity<T> success(T data) {
        return new ResultEntity<T>(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMessage(), data, System.currentTimeMillis());

    }

    public static <T> ResultEntity<T> success(T data, String message) {
        return new ResultEntity<T>(ResponseCodeEnum.SUCCESS.getCode(), message, data, System.currentTimeMillis());

    }


    public static <T> ResultEntity<T> warn() {
        return new ResultEntity<T>(ResponseCodeEnum.WARN.getCode(), ResponseCodeEnum.WARN.getMessage(), null, System.currentTimeMillis());
    }

    public static <T> ResultEntity<T> warn(String message) {
        return new ResultEntity<T>(ResponseCodeEnum.WARN.getCode(), message, null, System.currentTimeMillis());
    }

    public static <T> ResultEntity<T> warn(T data, String message) {
        return new ResultEntity<T>(ResponseCodeEnum.WARN.getCode(), message, data, System.currentTimeMillis());
    }

    public static <T> ResultEntity<T> fail() {
        return new ResultEntity<T>(ResponseCodeEnum.ERROR.getCode(), ResponseCodeEnum.ERROR.getMessage(), null, System.currentTimeMillis());
    }

    public static <T> ResultEntity<T> fail(String message) {
        return new ResultEntity<T>(ResponseCodeEnum.ERROR.getCode(), message, null, System.currentTimeMillis());
    }

    public static <T> ResultEntity<T> fail(T data, String message) {
        return new ResultEntity<T>(ResponseCodeEnum.ERROR.getCode(), message, data, System.currentTimeMillis());
    }

    public static <T> ResultEntity<T> fail(Integer code, T data, String message) {
        return new ResultEntity<T>(code, message, data, System.currentTimeMillis());
    }

    public static <T> ResultEntity<T> fail(Integer code, String message) {
        return new ResultEntity<T>(code, message,System.currentTimeMillis());
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }
}
